# encoding: UTF-8

class Admin::NodesController < ApplicationController
  before_filter :user_signed_in?
  
  def index
    @nodes = Node.all
    set_seo_meta '分类管理'
  end

  def new
    set_seo_meta '分类编辑'
  end
  
  def create
    @node = Node.new(params[:session])
    if @node.save!
      redirect_to nodes_path, notice: '新增成功!'
    else
      redirect_referrer_or_default default
    end  
  end

  def edit
    @node = Node.find(params[:id]) 
    set_seo_meta '分类修改'
  end

  def update
    @node = Node.find(params[:id])
    if @node.update_attributes!(params[:session])
      redirect_to nodes_path, notice:'修改成功'
    else
      redirect_referrer_or_defautl default
    end
  end

  def destory
    if Node.delete(params[:id])
      redirect_to nodes_path, notice:'删除成功'
    else
      redirect_referrer_or_default default
    end  
  end

end
